# -*- coding:utf-8 -*-
"""
Python 3.7
Author：刘爽、何若溥
Time：2022/08/23
"""

import os
import shutil
from common.path import CONFIGPATH, PICPATH


def getProperties(file_name):
    properties = {}
    with open(file_name, "r", encoding="utf-8") as f:
        for line in f:
            if line.find("=") > 0:
                strs = line.replace("\n", "").split("=")
                properties[strs[0]] = strs[1]
    return properties


def clearDir(filepath):
    if not os.path.exists(filepath):
        os.mkdir(filepath)
    else:
        shutil.rmtree(filepath)
        os.mkdir(filepath)


def getLocalPicPath(chart_name):
    return os.path.join(PICPATH, f"{chart_name}.png")


def getRemotePicPath(chart_name):
    return f"/root/bug_statistic/{chart_name}.png"


def getChartRemoteUrl(chart_name):
    return f'http://139.196.253.94/bug_statistic/{chart_name}.png'


def getBugUrl(project_id):
    return f'https://ifzendao.gwm.cn/zentao/bug-browse-{project_id}--byModule-5331.html'


def getDingAccessToken(ding_url, access_token):
    return f"{ding_url}?access_token={access_token}"


if __name__ == '__main__':
    pro_data = getProperties(CONFIGPATH)
    print(pro_data)
